function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

$(function () {
    $(".news_review").submit(function (e) {
        e.preventDefault();

        // 组织参数
        var params = {
            news_id: $('input[name=news_id]').val(),
            // :checked 表示获取当前被勾选的input框
            status: $('input[name=status]:checked').val(),
            reason: $('textarea[name=reason]').val(),
        };

        // TODO 新闻审核提交
        $.ajax({
            url: "/admin/news_review_detail",
            data: JSON.stringify(params),
            method: "POST",
            contentType: "application/json",
            dataType: "json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token"),
            },
            success: function (resp) {
                if (resp.errno == 0) {
                    // 操作成功
                    location.href = "/admin/news_review"
                } else {
                    alert(resp.errmsg)
                }
            }
        })
    })
});

// 点击取消，返回上一页
function cancel() {
    history.go(-1);
}